package com.kinyx.framework.db.sentence.res.demo.insert;

import org.junit.Assert;
import org.junit.Test;

import com.kinyx.framework.db.configs.DBConfigsHelper;
import com.kinyx.framework.db.sentence.res.KINSERT;
import com.kinyx.framework.db.sentence.res.KSQLBuilder;
import com.kinyx.test.entities.impl.DemoEntityR;

public class INSERT_Tester {

	final KINSERT insert = KSQLBuilder.insert(DemoEntityR.class);

	String defaultSentenceSQL = "INSERT INTO T_DEMO";

	protected void test(final KINSERT insert, final String expectedSentence, final String expectedString) {
		Assert.assertEquals(expectedSentence, insert.getSentence(DBConfigsHelper.getDBConfigs(null)));
		Assert.assertEquals(expectedString, insert.toString());
	}

	String defaultStringSQL = "SQL: [" + this.defaultSentenceSQL + "], params: []";

	@Test
	public void test0() {
		this.test(this.insert, this.defaultSentenceSQL, this.defaultStringSQL);
	}

	@Test
	public void demo1() {
		final String sentence = "INSERT INTO T_DEMO (ID) VALUES (?)";
		final String str = "SQL: [" + sentence + "], params: [foo]";
		this.test(//
				KSQLBuilder.insert(DemoEntityR.class)//
						.values(DemoEntityR.id, "foo")//
				, sentence, str);
	}

	@Test
	public void test_values1() {
		final String sentence = this.defaultSentenceSQL + " (ID) VALUES (?)";
		final String str = "SQL: [" + sentence + "], params: [foo]";
		this.test(this.insert.values(DemoEntityR.id, "foo"), sentence, str);
	}

	@Test
	public void test_values2() {
		final String sentence = this.defaultSentenceSQL + " (ID, USING_STATUS) VALUES (?, ?)";
		final String str = "SQL: [" + sentence + "], params: [foo, bar]";
		this.test(this.insert.values(DemoEntityR.id, "foo").values(DemoEntityR.usingStatus, "bar"), sentence, str);
	}

}
